using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GamePanel : BasePanel<GamePanel>
{
    public CustomGUILabel score;
    public CustomGUILabel time;
    public CustomGUIButton btnSetting;
    public CustomGUIButton btnClose;
    public CustomGUITexture hp;


    public int nowScore = 0;
    public float nowTime = 0;
    public int maxHP = 100;
    public float weight = 250;

    private int timeTemp = 0;

    // Start is called before the first frame update
    void Start()
    {
        btnClose.clickEvent += () =>
        {
            Time.timeScale = 0;
            //弹出退出按钮
            QuitPanel.Instance.ShowMe();
        };

        btnSetting.clickEvent += () =>
        {
            Time.timeScale = 0;
            //设置面板
            SettingPanel.Instance.ShowMe();
        };
    }

    public void AddScore(int value)
    {
        nowScore += 0;
        score.content.text = value.ToString();
    }

    // Update is called once per frame
    void Update()
    {
        nowTime += Time.deltaTime;
        //转换时分秒
        string timeStr = TransTime(nowTime);
        time.content.text = timeStr;
    }

    private string TransTime(float value)
    {
        timeTemp = (int)value;

        string timeStr = "";

        if (timeTemp / 3600 > 0)
        {
            timeStr += timeTemp / 3600 + "时";
        }

        if (timeTemp % 3600 / 60 > 0 || timeStr != "")
        {
            timeStr += timeTemp % 3600 / 60 + "分";
        }

        timeStr += timeTemp % 60 + "秒";
        return timeStr;
    }


    /// <summary>
    /// 更新血条
    /// </summary>
    /// <param name="nowHP"></param>
    public void UpdateHP(int nowHP)
    {
        hp.guiPos.width = (float)nowHP / maxHP * weight;
    }
    
}